package com.wwwarehouse.contract.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wwwarehouse.contract.bean.ChooseModuleBean;

import java.util.List;

import contract.wwwarehouse.com.contract.R;

import static android.media.CamcorderProfile.get;

/**
 * Created by zhenwang.xiang on 2017/9/23.
 * Description:选择行业RecyclerView的Adapter
 */

public class SelectIndustryAdapter extends BaseAdapter {

    private  List<ChooseModuleBean.ModuleList.BeanList> mData;
    private Context mContext;
    private ViewHolder mHolder;

    public SelectIndustryAdapter( List<ChooseModuleBean.ModuleList.BeanList> data, Context context) {
        this.mData = data;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.contract_item_rv_authority_distribute, null);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }
        mHolder.mBtnSelect.setText(mData.get(position).getName());
        boolean isSelected = mData.get(position).isSelect();
        if (isSelected) {
            if (mData.get(position).getSelected() == 1) {
                mHolder.mBtnSelect.setTextColor(mContext.getResources().getColor(R.color.common_color_c7_96999e));
                mHolder.mRlItem.setBackground(mContext.getResources().getDrawable(R.drawable.text_view_unchecked_background));
            } else {
                mHolder.mBtnSelect.setTextColor(mContext.getResources().getColor(R.color.common_color_c1_337cff));
                mHolder.mRlItem.setBackground(mContext.getResources().getDrawable(R.drawable.stroke_blue_sold_whit_background));
            }
        } else {
            mHolder.mRlItem.setBackground(mContext.getResources().getDrawable(R.drawable.text_view_gray_background));
            mHolder.mBtnSelect.setTextColor(mContext.getResources().getColor(R.color.common_color_c7_96999e));
        }
        return convertView;
    }

    class ViewHolder {
        TextView mBtnSelect;
        RelativeLayout mRlItem;

        public ViewHolder(View view) {
            mRlItem = (RelativeLayout) view.findViewById(R.id.rl_item);
            mBtnSelect = (TextView) view.findViewById(R.id.btn_select);
        }
    }
}
